package com.usian.controller;

import com.usian.pojo.User;
import com.usian.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpSession;

@Controller
@RequestMapping("/users")
public class UserController {

    @Autowired
    private UserService userService;

    @RequestMapping("/login")
    public String login(Model model, User users, HttpSession session) {
        User user = userService.login(users);

        if (user != null) {
            if (user.getRoleId() == 1) {
                session.setAttribute("user", user);
                return "redirect:/good/findAll";
            } else if (user.getRoleId() == 2) {
                session.setAttribute("user", user);
                return "redirect:/good/shenhe";
            }
        }
        return "login";
    }

}
